<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片 -->
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getGoodsList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getGoodsList"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span='4'>
            <el-button type="primary" @click="goAddPage">添加商品</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="goodsList" stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="商品名称" prop="goods_name"></el-table-column>
        <el-table-column
          label="商品价格"
          prop="goods_price"
          width="95px"
        ></el-table-column>
        <el-table-column
          label="商品重量"
          prop="goods_weight"
          width="80px"
        ></el-table-column>
        <el-table-column label="创建时间" width="200px">
          <template slot-scope="scope">
            {{ scope.row.upd_time | dateFormate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="130px">
          <el-button type="primary" icon="el-icon-edit" size="mini">
          </el-button>
          <el-button type="danger" icon="el-icon-delete" size="mini">
          </el-button>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="goodsSizeChange"
        @current-change="goodsCurrentChange"
        :current-page="this.queryInfo.pagenum"
        :page-size="this.queryInfo.pagesize"
        :page-sizes="[3, 5, 10, 15]"
        layout="total,sizes,prev, pager, next, jumper"
        :total="this.total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
      },
      goodsList: [],
      total: 0,
    }
  },
  created() {
    this.getGoodsList()
  },
  methods: {
    async getGoodsList() {
      const { data: res } = await this.$axios.get('goods', {
        params: this.queryInfo,
      })
      console.log(res.data)
      this.goodsList = res.data.goods
      this.total = res.data.total
    },
    goodsSizeChange(val) {
      this.queryInfo.pagesize = val
      this.getGoodsList()
    },
    goodsCurrentChange(val) {
      this.queryInfo.pagenum = val
      this.getGoodsList()
    },
    goAddPage(){
        this.$router.push('/goods/add')
    }
  },
}
</script>
<style lang="less" scoped>
.el-col{
    margin: 10px;
}
</style>